package com.candy.control;

import com.candy.service.UserInfoService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.LinkedList;

@WebServlet("/getUserifoes")
public class GetUserInfoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//       处理中文乱码问题
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        接收用户传递进来的参数
       String username= req.getParameter("username");
//       调用业务逻辑处理层
        UserInfoService service=new UserInfoService();
        LinkedList<LinkedHashMap<String,Object>> userinfoes= service.getUserInfo(username);
//        将用户信息传递到前台
//        将用户信息存放在session中
        req.getSession().setAttribute("userinfoes",userinfoes);
//       跳转页面
        req.getRequestDispatcher("userInfoManager.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
